package hw724;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.stream.IntStream;

/*斗地主*/
public class zuoye8 {
	public static void main(String[] args) {
		ArrayList<String> poker=new ArrayList<String>();
		String[] colors={"♠","♣","♦","♥"};
		String[] numbers={"2","A","K","Q","J","10",
				"9","8","7","6","5","4","3"};
		poker.add("大王");
		poker.add("小王");
		
		//流式生成牌
		IntStream.range(0, numbers.length).forEach(i->{
			for(String color:colors){ poker.add(color+numbers[i]);}
		});
		/*for(String number:numbers){
			for(String color:colors){
				poker.add(color+number);
			}
		}*/
		System.out.println(poker);
		
		Collections.shuffle(poker);
		System.out.println(poker);
		
		zuoye8_player p1=new zuoye8_player();p1.setName("dbw");
		zuoye8_player p2=new zuoye8_player();p2.setName("dbw1");
		zuoye8_player p3=new zuoye8_player();p3.setName("zky");
		ArrayList<String> dipai=new ArrayList<String>();
		
		//摸牌
		for(int i=0;i<poker.size();i++){
			String p=poker.get(i);
			if(i>=51){
				dipai.add(p);
				}else if(i%3==0){
					p1.getPoker().add(p);
				}else if(i%3==1){
					p2.getPoker().add(p);
				}else if(i%3==2){
					p3.getPoker().add(p);
				}
			}
		//看牌
		
		//创建hashmap
		HashMap<String, ArrayList<String>> map=new HashMap<>();
		map.put(p1.getName(), p1.getPoker());
		map.put(p2.getName(), p2.getPoker());
		map.put(p3.getName(), p3.getPoker());
		
		//牌的排序流式
		map.forEach((playerName,playerPorker)->{
			sortPoker(playerPorker);
			System.out.println(playerName + "的牌: " + playerPorker);});
		
		System.out.println("底牌:"+dipai);
		
	}

	private static void sortPoker(ArrayList<String> playerPoker) {
		playerPoker.sort(Comparator.comparingInt(zuoye8::getRank));
	
}
	private static int getRank(String card) {
        String numberPart = card.replaceAll("[♠♣♦♥]", ""); // 去掉花色
        if (numberPart.equals("小王")) return 15;
        if (numberPart.equals("大王")) return 16;
        String[] ranks = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (int i = 0; i < ranks.length; i++) {
            if (numberPart.equals(ranks[i])) return i;
        }
        return 0; // 默认情况
    }
}
